#!/bin/bash
#更新spring-boot应用

source /etc/profile
. $BEETLE_SHELL_PATH/error.sh

projectName=$1

if [ ! ${projectName} ]
then
    error_exit "参数存在空值projectName"
fi

# 分支名
branch=$2
silent=$3

codePath=/usr/local/beetle/code/${projectName}
workPath=/usr/local/spring-boot
configPath=/usr/local/beetle/config/${projectName}
bakPath=/usr/beetle/appbak/${projectName}
bakName=${projectName}
logPath=/usr/beetle/applogs/${projectName}/${projectName}.log


bash $BEETLE_SHELL_PATH/git_checkout.sh ${codePath} ${branch} || error_exit

bash $BEETLE_SHELL_PATH/bak.sh ${workPath} ${projectName} ${bakPath} ${bakName} || error_exit

cd ${codePath} || error_exit

mvn -U clean compile package -DskipTests || error_exit

springboot.sh stop ${workPath}/${projectName}/${projectName}.jar

rm -rf ${workPath}/${projectName}/* || error_exit

cp target/${projectName}.jar ${workPath}/${projectName}/ || error_exit

cp ${configPath}/* ${workPath}/${projectName}/ || error_exit

springboot.sh start ${workPath}/${projectName}/${projectName}.jar 


if [ ! ${silent} ]
then
    sleep 3

	tail -fn20 ${logPath}
fi

